%%%-----------------------------------
%%% @Module  : pt_22
%%% @Author  : xws
%%% @Created : 2016.9.22
%%% @Description: 
%%%-----------------------------------
-module(pt_22).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_22_hundred_douniu.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%% 22000 请求进入百人牛牛
read(22000, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_enter_hundred_douniu, Bin),	
	#c2s_enter_hundred_douniu{
        player_id = PlayerId
    } = ClientData,
    {ok, [PlayerId]};

%% 22001 同步游戏押注信息
read(22001, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_sync_yazhu_data, Bin),	
	#c2s_sync_yazhu_data{room_id = RoomId} = ClientData,
    {ok, [RoomId]};

%% 22002 获取上庄列表
read(22002, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_banker_wait_list, Bin),  
    #c2s_get_banker_wait_list{
        room_id = RoomId
    } = ClientData,
    {ok, [RoomId]};

%% 22003 玩家坐下
read(22003, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_sit_on, Bin),  
    #c2s_sit_on{room_id=RoomId, pos=Pos} = ClientData,
    {ok, [RoomId, Pos]};

%% 22004 玩家起来
read(22004, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_stand_up, Bin),  
    #c2s_stand_up{room_id = RoomId} = ClientData,
    {ok, [RoomId]};

%% 22005 玩家押注
read(22005, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_yazhu_coin, Bin),  
    #c2s_yazhu_coin{yazhu_list = YazhuList} = ClientData,
    YazhuList1 = [{Area, Coin} || #proto_area_yazhu{area=Area, coin=Coin} <- YazhuList],
    {ok, [YazhuList1]};

%% 22006 上庄
read(22006, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_go_banker, Bin),  
    #c2s_go_banker{room_id = RoomId, coin = Coin, use_card = UseCard} = ClientData,
    {ok, [RoomId, Coin, UseCard]};

%% 22007 下庄
read(22007, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_out_banker, Bin),  
    #c2s_out_banker{room_id=RoomId} = ClientData,
    {ok, [RoomId]};


%% 22008 强制退出游戏
read(22008, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_force_exit_hundred_douniu, Bin),  
    #c2s_force_exit_hundred_douniu{player_id=PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 22014 同步房间数据
read(22014, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_sync_room_state, Bin),
    #c2s_sync_room_state{room_id = RoomID} = ClientData,
    {ok, [RoomID]};

%% 22019 获取玩家区域押注数据
read(22019, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_areas_stake_coin, Bin),  
    #c2s_get_areas_stake_coin{player_id=PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 22021 获取玩家列表
read(22021, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_player_list, Bin),  
    #c2s_get_player_list{player_id=PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 22031玩家聊天
read(22031, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_niuniu_face_talk, Bin),  
    {ok, [ClientData]};

%% 22032 返利查询
read(22032, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_niuniu_reback_info, Bin),  
    {ok, [ClientData]};

%% 22035 魔法表情
read(22035, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_niuniu_emoticon, Bin),
    {ok, [ClientData]};

%% 22036 区域信息下发
read(22037, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_niuniu_area_stake_info, Bin),
    #c2s_niuniu_area_stake_info{room_id = RoomID} = ClientData,
    {ok, [RoomID]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%
%% 22000 请求进入百人牛牛
write(22000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_enter_hundred_douniu, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22000, ServerData)};

%% 22001 同步游戏押注信息
write(22001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_sync_yazhu_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22001, ServerData)};

%% 22002 s2c 获取上庄列表
write(22002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_banker_wait_list, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22002, ServerData)};

%% 22003 玩家坐下
write(22003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_sit_on, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22003, ServerData)};

%% 22004 玩家起来
write(22004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_stand_up, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22004, ServerData)};

%% 22005 玩家押注
write(22005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_yazhu_coin, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22005, ServerData)};

%% 22006 上庄
write(22006, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_go_banker, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22006, ServerData)};

%% 22007 下庄
write(22007, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_out_banker, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22007, ServerData)};

%% 22009 广播房间状态
write(22009, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_room_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22009, ServerData)};

% 22010 广播开奖信息
write(22010, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_kaijiang_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22010, ServerData)};

%% 22011 广播结算信息
write(22011, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_jiesuan_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22011, ServerData)};

%% 22012 广播玩家上座
write(22012, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_sit_on, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22012, ServerData)};

%% 22013 广播玩家下座
write(22013, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_stand_up, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22013, ServerData)};

%% 22014 同步房间数据
write(22014, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_sync_room_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22014, ServerData)};

%% 22015 广播玩家结算信息
write(22015, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_player_jiesuan_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22015, ServerData)};

%% 22016 通知玩家成为庄家
write(22016, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_notify_player_go_banker, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22016, ServerData)};

%% 22017 通知玩家下庄
write(22017, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_notify_player_out_banker, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22017, ServerData)};

%% 22018 通知玩家推出游戏
write(22018, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_exit_hundred_douniu, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22018, ServerData)};

%% 22019 获取玩家区域押注数据
write(22019, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_areas_stake_coin, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22019, ServerData)};

%% 22020 广播百人牛牛上庄长度
write(22020, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_broadcast_banker_len, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22020, ServerData)};

%% 22021 获取玩家列表
write(22021, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_player_list, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22021, ServerData)};


%% 22031 玩家聊天
write(22031, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_face_talk, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22031, ServerData)};


%% 22032 返利查询
write(22032, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_reback_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22032, ServerData)};


%% 22033 返利通知
write(22033, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_reback_notify, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22033, ServerData)};


%% 22034　结算通知
write(22034, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_caculate_ret, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22034, ServerData)};


%% 22035　魔法表情
write(22035, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_emoticon, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22035, ServerData)};

%% 22036　下注信息下发
write(22036, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_stake_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22036, ServerData)};

%% 22037　区域信息下发
write(22037, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_niuniu_area_stake_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(22037, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_22 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.
